Skip to content

Advance usage features for general MerkleCRDT applications#337

Merged
hsanjuan merged 7 commits intomasterfrom
feat/custom-deltas
Mar 5, 2026
Merged

Advance usage features for general MerkleCRDT applications#337
hsanjuan merged 7 commits intomasterfrom
feat/custom-deltas

Conversation

@hsanjuan
Copy link
Copy Markdown
Collaborator

@hsanjuan hsanjuan commented Mar 3, 2026

Feat: allow advanced usage for general MerkleCRDT applicaions

This commit enables advanced usecases by opening access to previously internal operations and options. A MerkleCRDT-based Set is still the base but:

  • We can now use custom Deltas (interface added): this allows storing any custom information in the CRDT tree.
  • We can now manually create and submit deltas (to complement the above)
  • We can interact directly with the internal Set.
  • Heads can be managed manually.
  • The CRDT now supports DAGNames, which allows to have separate DAGs (namespaces), in the same CRDT, each of them with their own head(s).
    • Additionally, some key functions can now return errors.

This is all is possible via a new MerkleCRDT type and custom deltas. The Datastore type and general library usage remains the same as before.

@hsanjuan hsanjuan self-assigned this Mar 3, 2026
Copy link
Copy Markdown
Collaborator Author

@hsanjuan hsanjuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some smallish things I will be fixing now.

@guillaumemichel guillaumemichel self-requested a review March 4, 2026 11:48
Copy link
Copy Markdown
Contributor

@guillaumemichel guillaumemichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments

Comment on lines +202 to +206
// sort.Slice(heads, func(i, j int) bool {
// ci := heads[i].Bytes()
// cj := heads[j].Bytes()
// return bytes.Compare(ci, cj) < 0
// })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reasons to remove the sorting? If yes, remove fully.

hsanjuan and others added 7 commits March 5, 2026 11:14
This commit enables advanced usecases by opening access to previously internal
operations and options. A MerkleCRDT-based Set is still the base but:

* We can now use custom Deltas (interface added): this allows storing any custom information in the CRDT tree.
* We can now manually create and submit deltas (to complement the above)
* We can interact directly with the internal Set.

This is possible via a new MerkleCRDT type, which wraps the Datastore
type. The Datastore type and general library usage remains the same as before.
This introduces support for CRDT-DAG segmentation when using custom deltas.

It works as follows: delta.GetDagName() returns a name for a dag
segment. Each CRDT-head belongs to the DAG segment specified by its
delta and any new head only references previous heads of the same DAG segment.

The result is that we have separate dags, one per DagName, with all
the nodes in them belonging to the same DagName. Deltas can still
reference any keys etc. but this way we can create separate
crdt-"histories" that run in parallel.

Note that at any time, there will be at least as many heads as
different DagNames, so having many DagNames will impact the size of
broadcasts as they will include all the heads and new writes will not
consolidate them into a single head.
MerkleCRDT.Publish() applies delta to DAG and returns the CID of the
resulting root node.

Additionally, IsProcessed(ctx, cid) is exported so that it is possible
to check from the outside whether a cid has been traversed.
Set height to maxHeight + 1 of heads in that dag only.
This way the user also gets information about the height and DagName.
@hsanjuan hsanjuan force-pushed the feat/custom-deltas branch from 29e0247 to 1720fe9 Compare March 5, 2026 10:18
@hsanjuan hsanjuan enabled auto-merge March 5, 2026 10:18
@hsanjuan hsanjuan disabled auto-merge March 5, 2026 10:20
@hsanjuan hsanjuan merged commit 2257cab into master Mar 5, 2026
5 checks passed
@hsanjuan hsanjuan deleted the feat/custom-deltas branch March 5, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants